import Vue from 'vue'
import store from '../store'
import axios from 'axios'
import config from '../config'

Vue.prototype.$axios = axios
axios.interceptors.request.use(config => {
  store.commit('app_openLoading')
  let userToken = localStorage.getItem('token') || ''
  let LanguageType = JSON.parse(sessionStorage.getItem('lang')).lang
  config.headers['X-USER-TOKEN'] = userToken
  config.headers['LanguageType'] = LanguageType
  return config
}, function (error) {
  // 处理响应失败
  return Promise.reject(error)
})
axios.interceptors.response.use(data => {
  if (data.status === 200) {
    store.commit('app_closeLoading')
  }
  if (data.status === 500) {
    store.commit('app_closeLoading')
  }
  if (data.status === 404) {
    store.commit('app_closeLoading')
  }
  return data
}, function (error) {
  // 处理响应失败
  return Promise.reject(error)
})
export default {
  params: { // 每一个连接都跟着的东西，查询字符串
    clientCode: 'wechat'
  },
  axios: axios,
  HOST: config.URL
}
